package com.chocus.core.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.fasterxml.jackson.annotation.JsonIgnore;

/**
 * 购物车对象
 * 
 * @author Administrator
 *
 */
public class BuyerCart implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * 结果集
	 */
	private List<BuyerItem> items = new ArrayList<BuyerItem>();

	/**
	 * 将item放入list
	 * 
	 * @param buyerItem
	 */
	public void setItem(BuyerItem buyerItem) {
		if (items.contains(buyerItem)) {
			for (BuyerItem bi : items) {
				if (bi.equals(buyerItem)) {
					bi.setAmount(bi.getAmount() + buyerItem.getAmount());
				}
			}
		} else {
			items.add(buyerItem);
		}
	}

	public List<BuyerItem> getItems() {
		return items;
	}

	public void setItems(List<BuyerItem> items) {
		this.items = items;
	}

	/**
	 * 小计-商品数量
	 */
	@JsonIgnore
	public Integer getCount() {
		Integer result = 0;
		for (BuyerItem buyerItem : items) {
			result += buyerItem.getAmount();
		}
		return result;
	}

	/**
	 * 小计-商品金额
	 */
	@JsonIgnore
	public Float getPrice() {
		Float result = 0f;
		for (BuyerItem buyerItem : items) {
			result += buyerItem.getAmount() * buyerItem.getSku().getPrice();
		}
		return result;
	}

	/**
	 * 小计-运费
	 */
	@JsonIgnore
	public Float getFee() {
		Float result = 0f;
		if (getPrice() < 70) {
			result = 5f;
		}
		return result;
	}

	/**
	 * 小计-应付总额
	 */
	@JsonIgnore
	public Float getTotal() {
		return getPrice() + getFee();
	}
}
